<template>
    <Banner :bannerImg="bannerImg">
        <div class="detail_content-desc maxWidth1400">
            <h3>
                {{ state.articleInfo?.title }}
            </h3>
            <span class="news_detail-date">{{
                state.articleInfo?.publishDate?.split(" ")[0]
            }}</span>
        </div>
    </Banner>
    <div class="article_detail">
        <div
            class="article_detail-area maxWidth1400"
            v-html="state.articleInfo?.context"
        ></div>
    </div>
</template>

<script setup>
import bannerImg from "/assets/image/news/news_banner.jpg";
import { ARTICLE_TYPE_MAP } from "~/utils/const";

const route = useRoute();
const router = useRouter();
const { locale } = useI18n();
const state = reactive({
    articleInfo: {},
    articleList: [],
});
const getArticleInfo = async (id) => {
    const res = await useGET(`/v1/aricle/articleInfo/${id}`);
    state.articleInfo = { ...res?.data };
};

const getNewsList = async (type) => {
    const res = await useGET("/v1/aricle/page", {
        query: {
            page: 1,
            limit: 99,
            type,
        },
    });
    state.dataList = res?.rows.length ? res.rows : [];
};
const handleArticleClick = (id) => {
    router.push({
        path: `/news/${route.params.slug}`,
        query: {
            id,
        },
    });
};

watchEffect(() => {
    if (route.query.id || locale.value) {
        getArticleInfo(route.query.id);
        getNewsList(ARTICLE_TYPE_MAP[route.params.slug]);
    }
});
</script>

<style lang="scss">
.article_detail {
    width: 100%;
    padding-bottom: 60px;
    background-color: #fafafc;
    .article_detail-area {
        position: relative;
        z-index: 9;
        margin-top: -70px;
        min-height: 400px;
        padding: 70px 124px 94px;
        background-color: #fff;
        p {
            font-size: 14px;
            line-height: 30px;
            letter-spacing: 0px;
            color: #59595f;
            img {
                max-width: 100%;
                display: inline-block;
            }
        }
        img {
            max-width: 100%;
            display: inline-block;
        }
    }
}
.detail_content-desc {
    position: absolute;
    bottom: 100px;
    left: 0;
    right: 0;
    text-align: center;
    color: #fff;

    h3 {
        width: 80%;
        font-size: 28px;
        line-height: 1.48;
        margin: 0 auto 8px;
    }
    .news_detail-date {
        background: url("assets/image/icon-clock.png") no-repeat left center;
        background-size: 16px;
        padding: 0 16px 0 22px;
    }
}
</style>
